﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using outREACH.App_Code;

namespace outREACH
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                if (Session["UserName"] != null)
                {
                    Label lbl1 = (Label)Master.FindControl("Label1");
                    lbl1.Text = "Welcome " + Session["Username"].ToString() + "!";
                    Label lbl2 = (Label)Master.FindControl("Name");
                    Users u = Users.GetName(Session["Username"].ToString());
                    lbl2.Text = u.firstName + " " + u.lastName;
                    Label lbl3 = (Label)Master.FindControl("Country");
                    lbl3.Text = Session["country"].ToString();
                    Button btn3 = (Button)Master.FindControl("Button4");
                    if (User.IsInRole("admin"))
                    {
                        btn3.Visible = true;
                    }
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            EduForum ef = new EduForum();
            string name = Session["userName"].ToString();
            ef.title = TextBox1.Text;
            ef.post = TextBox2.Text;
            ef.userName = name;
            DateTime myDateTime = DateTime.Now;
            //DateTime myDateTime2 = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
            ef.dateTime = myDateTime;
            ef.dateTimeUpdated = myDateTime;
            ef.category = "Education";
            ef.noOfReply = 0;
            string path = "";
            string iname = "";
            string country = "";
            List<Users> results = Users.GetUser();
            foreach (Users u in results)
            {
                if (Session["Username"].ToString() == u.userName.ToString())
                {
                    path = u.imagePath.ToString();
                    iname = u.imageName.ToString();
                    country = u.country.ToString();
                }
            }
            ef.imagePath = path;
            ef.imageName = iname;
            ef.country = country;
                //DateTime.Parse(DateTime.Now, ,"{0::MM/dd/yy HH:mm:ss tt}");
            EduForum.NewThread(ef);
            Annoucement.InsertAnnoucement(name, TextBox1.Text, TextBox2.Text, myDateTime, "Education", "", "", "", "", "", 0, "", "");
            EduAnnouncement.InsertEduAnnoucement(TextBox1.Text, TextBox2.Text, myDateTime, name, "", "", "");
            Response.Redirect("~/Education/EducationForum.aspx");
        }
    }
}